/********************************************************/
/*	Author:		gong_libin			*/
/*	Date:		2017_11_01			*/
/*	File:		CmAdxDef.h			*/
/********************************************************/

#ifndef	_CMADXDEF_H
#define	_CMADXDEF_H

#include <vector>
#include "CmMap.h"
#include "CmSet.h"
#include "CmUtil.h"

typedef std::string		CMSTR_C;
typedef CmCls::CCmSet		CMSET_C;
typedef std::vector<CMSTR_C>	CMVEC_C;
typedef CmCls::CCmMap<CMSTR_C, CMSTR_C, CmCls::CMMAPSTRING_O>	CMMAP_C;

typedef struct tagCmAdxMsg
{
	UINT	m_uiMsg;
	UCHAR	m_uszMsg[CM_KBYTES8];
}CMADXMSG_S;

typedef struct tagCmAdxPara
{
	CMMAP_C*	m_pCAdxLog;
	CMADXMSG_S	m_stSspReq;
	CMADXMSG_S	m_stDspReq;
	CMADXMSG_S	m_stDspRes;
	CMADXMSG_S	m_stSspRes;

	tagCmAdxPara() {
		m_pCAdxLog = new CMMAP_C();
	};

	~tagCmAdxPara() {
		delete m_pCAdxLog;
	}
}CMADXPARA_S;

typedef struct tagCmAdxLog
{
	CMSTR_C	m_CMsgId;	// messageId
	ULONG	m_ulMsgTim;	// messageTime
	UINT	m_uiMsgType;	// messageType 2000:normal request, 2001:dsp request, 2002:response, 2003:imp, 2004:click
	CMSTR_C	m_CDid;		// developerId
	CMSTR_C	m_CAid;		// pandoraAppId
	CMSTR_C	m_CEid;		// pandoraExhibitId
	CMSTR_C	m_CCid;		// pandoraChannelId
	CMSTR_C	m_CIP;		// clientIp
	CMSTR_C	m_CUa;		// clientUa
	CMSTR_C	m_CUid;		// clientAppUserId
	CMSTR_C	m_CImei;	// clientImei
	CMSTR_C	m_CAdvId;	// adId
	CMSTR_C	m_CCrtId;	// adResourceId
	UINT	m_uiAdvType;	// adResourceType 1:focus, 2:stream
	UINT	m_uiAdvSource;	// adSourceId 0:self, 1-N:DSP ID
	UINT	m_uiAdvPrice;	// adPrice
	CMSTR_C	m_CAdCtxtId;	// adContextId
	UINT	m_uiAdvResCode;	// adResponseCode 1000:normal, 1001:bid success, 2000:failure
	UINT	m_uiAdvBidMeth;	// adBillingMethod 1:cpc, 2:cpm, 3:cpd

	tagCmAdxLog() {
		m_uiMsgType = 0;
		m_uiAdvType = 0;
		m_uiAdvSource = 0;
		m_uiAdvPrice = 0;
		m_uiAdvResCode = 0;
		m_uiAdvBidMeth = 0;
	};
}CMADXLOG_S;

typedef struct tagCmAdxInfo
{
	// request.(base info)
	UINT	m_uiVer;	// version
	UINT	m_uiDsp;	// Dsp id
	CMSTR_C	m_CCtxtid;	// context id
	// request.(user info)
	CMSTR_C	m_CIP;		// user ip
	CMSTR_C m_CUid;		// user id
	CMSTR_C	m_CMac;		// user mac
	CMSTR_C	m_CGps;		// user gps
	CMSTR_C	m_CImei;	// user imei
	CMSTR_C	m_CUa;		// user uagent
	// request.(adver info)
	CMSTR_C	m_CDid;		// developer id
	CMSTR_C	m_CAid;		// app id
	CMSTR_C	m_CEid;		// exhibition id
	CMSTR_C	m_CCid;		// channel id
	CMSTR_C	m_CCats;	// category ids
	CMSTR_C	m_CType;	// 1:focus, 2:stream
	CMSTR_C	m_CWidth;	// width
	CMSTR_C	m_CHeight;	// height
	CMSTR_C	m_CScaling;	// width/height
	UINT	m_uiCrtView;	// 1:image, 2:video
	UINT	m_uiMinPrice;	// min price

	// response.(adver info)
	CMSTR_C	m_CAdvId;	// adver id
	CMSTR_C	m_CDesUrl;	// destination url
	CMSTR_C	m_CClkUrl;	// click_through_url
	CMSTR_C	m_CSupUrl;	// supervisory url
	CMSTR_C	m_CExtend;	// extend data
	CMSTR_C	m_CCategory;	// category
	UINT	m_uiCode;	// 1000:return succ, 1001:have bid, 2000:failed
	UINT	m_uiMethod;	// 1:cpc, 2:cpm, 3:cpd
	UINT	m_uiMaxPrice;	// max price
	// response.(creative info)
	CMSTR_C	m_CCrtId;	// creative id
	CMSTR_C	m_CCrtTitle;	// creative title
	UINT	m_uiCrtType;	// 1:image, 2:video

	tagCmAdxInfo() {
		m_uiVer = 0;
		m_uiDsp = 0;
		m_uiCrtView = 0;
		m_uiMinPrice = 0;
		m_uiCode = 0;
		m_uiMethod = 0;
		m_uiMaxPrice = 0;
		m_uiCrtType = 0;
	};

	void operator = (tagCmAdxInfo* pstInfo) {
		// request.(base info)
		m_uiVer = pstInfo->m_uiVer;
		m_uiDsp = pstInfo->m_uiDsp;
		m_CCtxtid = pstInfo->m_CCtxtid;
		// request.(user info)
		m_CIP = pstInfo->m_CIP;
		m_CUid = pstInfo->m_CUid;
		m_CMac = pstInfo->m_CMac;
		m_CGps = pstInfo->m_CGps;
		m_CImei = pstInfo->m_CImei;
		m_CUa = pstInfo->m_CUa;
		// request.(adver info)
		m_CDid = pstInfo->m_CDid;
		m_CAid = pstInfo->m_CAid;
		m_CEid = pstInfo->m_CEid;
		m_CCid = pstInfo->m_CCid;
		m_CCats = pstInfo->m_CCats;
		m_CType = pstInfo->m_CType;
		m_CWidth = pstInfo->m_CWidth;
		m_CHeight = pstInfo->m_CHeight;
		m_CScaling = pstInfo->m_CScaling;
		m_uiCrtView = pstInfo->m_uiCrtView;
		m_uiMinPrice = pstInfo->m_uiMinPrice;

		// response.(adver info)
		m_CAdvId = pstInfo->m_CAdvId;
		m_CDesUrl = pstInfo->m_CDesUrl;
		m_CClkUrl = pstInfo->m_CClkUrl;
		m_CSupUrl = pstInfo->m_CSupUrl;
		m_CExtend = pstInfo->m_CExtend;
		m_CCategory = pstInfo->m_CCategory;
		m_uiCode = pstInfo->m_uiCode;
		m_uiMethod = pstInfo->m_uiMethod;
		m_uiMaxPrice = pstInfo->m_uiMaxPrice;
		// response.(creative info)
		m_CCrtId = pstInfo->m_CCrtId;
		m_CCrtTitle = pstInfo->m_CCrtTitle;
		m_uiCrtType = pstInfo->m_uiCrtType;
	}
}CMADXINFO_S;

#define	CM_ADF_SCPC		0x01	// cpc
#define	CM_ADF_SCPM		0x02	// cpm
#define	CM_ADF_SCPD		0x03	// cpd

#define	CM_ADF_RSUC		1000	// return succ
#define	CM_ADF_RFAL		2000	// return fail
#define	CM_ADF_HBID		1001	// have bidding

#define	CM_ADF_QNML		2000	// request
#define	CM_ADF_QDSP		2001	// dsp request
#define	CM_ADF_PDSP		2002	// dsp response
#define	CM_ADF_IDSP		2003	// dsp imp
#define	CM_ADF_CDSP		2004	// dsp click

#define	CM_ADF_TRES		{"adverId", "destinationUrl", "clickUrl", "SupervisoryUrl", "extendData", "category", "adResponseCode", "adBillingMethod", "maxPrice", "creativeId", "creativeTitle", "creativeType"}
#define	CM_ADF_TREQ		{"version", "adSourceId", "contextId", "ip", "uId", "mac", "gps", "imei", "uagent", "developerId", "appId", "exhibitId", "channelId", "categoryIds", "type", "maxWidth", "maxHeight", "scaling", "creativeView", "minPrice"}
#define	CM_ADF_TLOG		{"messageId", "messageTime", "messageType", "developerId", "pandoraAppId", "pandoraExhibitId", "pandoraChannelId", "clientIp", "clientUa", "clientAppUserId", "clientImei", "adId", "adResourseId", "adResourceType", "adSourceId", "adPrice", "adContextId", "adResponseCode", "adBillingMethod"}

#endif /* _CMADXDEF_H */
